package com.qf.efserver.device.controller;

import com.qf.common.core.common.R;
import com.qf.efserver.device.VO.DeviceVO;
import com.qf.efserver.device.param.AddDeviceParam;
import com.qf.efserver.device.param.UpdateDeviceParam;
import com.qf.efserver.device.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * --- 遇事不决，可问春风。春风不语，遵循己心。---
 *
 * @date 2024/11/13
 */
@RestController
@RequestMapping("/device")
@Api(tags = "设备api")
public class DeviceController {
    @Resource
    private DeviceService deviceService;

    /**
     * 通过登陆用户的Id查询相对应的数据
     *
     * @return
     *
     */
    //@NoLoginCheck
    @ApiOperation(value = "设备首页",
            notes = "根据token来查询用户的设备")
    @GetMapping("/selectDevice")
    private R<List<DeviceVO>> select(){
        List<DeviceVO> deviceVOS = deviceService.selectDeviceByUserId();
        return R.ok(deviceVOS);
    }

    @ApiOperation(value = "设备添加",
            notes = "添加用户的设备、每一个用户限制五台设备")
    @PostMapping("/addDevice")
    private R<AddDeviceParam> add(AddDeviceParam addDeviceParam){
        deviceService.addDevice(addDeviceParam);
        return R.ok();
    }
    @ApiOperation(value = "更改设备状态",
            notes = "更改用户的设备状态、只能有一台设备进行连接")
    @PostMapping("/updateDevice")
    private R update(UpdateDeviceParam updateDeviceParam){
        deviceService.updateDeviceById(updateDeviceParam);
        return R.ok();
    }
    @ApiOperation(value = "设备删除",
            notes = "删除用户的设备")
    @PostMapping("/deleteDevice")
    private R delete(Integer id){
        deviceService.deleteDeviceById(id);
        return R.ok();
    }
}
